package com.leyou.search.web;

import com.leyou.search.dto.SearchParamDTO;
import com.leyou.search.entity.Goods;
import com.leyou.search.serivce.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("goods")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping("suggestion")
    public Mono<List<String>> suggestName(@RequestParam("key") String key){

        return this.searchService.suggestName(key);
    }

    /**
     * 前台的分页查询及高亮等信息实现
     * @param searchParamDTO
     * @return
     */
    @PostMapping("list")
    public Mono<PageInfo<Goods>> loadData(@RequestBody SearchParamDTO searchParamDTO){
        return this.searchService.loadData(searchParamDTO);
    }

    @PostMapping("filter")
    public Mono<Map<String, List<?>>> loadFilter(@RequestBody SearchParamDTO searchParamDTO){
        return this.searchService.loadFilter(searchParamDTO);
    }
}
